


nameList = ["小张", "小王", "小李"]

'''
print(nameList[0])
print(nameList[1])
print(nameList[2])

testList = [1, "测试"] # 列表中可以存储混合类型
print(type(testList[0]))
print(type(testList[1]))
'''

'''
for name in nameList:
    print(name)


print(len(nameList))
'''

# 使用 while

'''
i = 0

while i < len(nameList):
    print(nameList[i])
    i += 1

'''

# 增 [append]

'''
print("----增加前, 列表的数据----")
for name in nameList:
    print(name)
print("----增加后, 列表的数据----")
nameTemp = input("请输入要增加的数据: ")
nameList.append(nameTemp) # 在末尾追加元素
for name in nameList:
    print(name)
'''

# 列表嵌套

'''
a = [1, 2]
b = [3, 4]
a.append(b) # 将列表当作一个元素进行追加
print(a)

a.extend(b) # 将列表拆散然后把拆散后 的每一个元素追加
print(a)
'''

# 增 [insert]

'''
a = [0, 1, 2]
a.insert(1, 3) # 第一个变量代表下标, 第二个表示元素
print(a)      # 指定位置插入元素
'''

# 删 [del] [pop] [remove]
'''
movieName = ["加勒比海盗", "复仇者联盟", "速度与激情", "x战警", "速度与激情"]
print("----删除前的电影, 列表的数据----")
for name in movieName:
    print(name)

# del movieName[2]   # 在指定位置删除一个元素
# movieName.pop()  # 弹出末尾最后一个元素
movieName.remove("速度与激情") # 直接删除指定内容的元素, 且当存在相同内容的元素时, 默认删除第一个

print("----删除后的电影, 列表的数据----")
for name in movieName:
    print(name)
'''

# 改
'''
nameList = ["11", "22", "33"]
print("----修改前, 列表的数据----")
for name in nameList:
    print(name)

nameList[2] = "tlgen" # 修改指定下标的元素内容

print("----修改后, 列表的数据----")
for name in nameList:
    print(name)
'''

# 查

'''
nameList = ["小张", "小飞", "小志"]

findName = "小志"

if findName in nameList:
    print("在名单中找到匹配的名字")
else:
    print("没有匹配项")
'''

'''
myList = ["a", "b", "c", "a", "b"]
print(myList.index("a", 1, 4)) # 这个内容 a 出现在 1 到 4 这个范围内吗, 如果存在就返回它所在的下标

# print(myList.index("a", 1, 3)) # 范围之间左闭右开 [1, 3) 不包含 3

myList = ["a", "b", "c", "a", "b"]
print(myList.count("b"))   # 统计某个元素出现的次数
'''

# 排序和反转
'''
a = [1, 2, 3, 4]
print(a)
a.reverse()    # 将列表所有元素反转
print(a)
a.sort()      # 升序排序
print(a)
a.sort(reverse=True) # 降序排序
print(a)
'''

# 嵌套
import random
# schoolNames = [[], [], []]  # 有3个元素的空列表
schoolNames = [["北京大学", "清华大学"], ["11", "22", "33"], ["小志", "小乔"]]
print(schoolNames[0])
print(schoolNames[0][0])

offices = [[], [], []]
names = ["A", "B", "C", "D", "E", "F", "G", "H"]

for name in names:
    index = random.randint(0, 2)
    offices[index].append(name)

i = 1
for office in offices:
    print(office)
    i += 1
    for name in office:
        print("%s"%name, end="\t")
    print("\n")
    print("-"*20)


